import { defineStore } from "pinia";
import { ref } from "vue";

const persist = {
  enabled: true,
  // 选择存储方式和内容
  strategies: [{ storage: sessionStorage }],
};

const useUserStore = defineStore(
  "user",
  () => {
    const token = ref("");
    const setToken = (val) => {
      token.value = val;
    };

    const userInfo = ref(null);
    const setUserInfo = (val) => {
      userInfo.value = val;
    };
    return { token, setToken, userInfo, setUserInfo };
  },
  { persist } //持久化存储，会把该store的内容存到sessionStorage
);

export default useUserStore;
